import Vue from 'vue'
import Vuex from 'vuex'
import util from '@/util/util'

Vue.use(Vuex)

const state = {
    CouponsMap:{},//优惠券列表       券字
    membershipMap:{},//会员卡列表    卡字
    storeMap:{},//商户信息
    CouponsPlayMap:{},//闪惠信息      惠字
    baiduMap:{}//商户经纬度
}

const mutations = {
    setGoodsDetailData(state,param){
        state.CouponsMap = param.CouponsMap;
        state.membershipMap = param.membershipMap;
        state.storeMap = param.storeMap;
        state.CouponsPlayMap = param.CouponsPlayMap;
        state.baiduMap = param.baiduMap;
    }
}

const actions = {

    /*
     *  resp.data
     *      CouponsMap      优惠券列表
     *      membershipMap   会员卡列表
     *      storeMap        商户信息
     */
    loadGoodsDetail(store,params){
        return new Promise((resolve,reject)=>{
            util.axiosPost('/service/consume/MerchantDetailServlet.do',params).then(resp=>{
                store.commit('setGoodsDetailData',resp.data);
                console.log(resp.data);
                resolve();
            });
        });
        
    },
    /**
     * 扫码进来的参数
     */
    membershipServelt(store,params){
        return util.axiosPost('/service/consume/MembershipServelt.do',params);
    }
}

const getters = {
    getCouponsMap(state){
        return state.CouponsMap;
    },
    getMembershipMap(state){
        return state.membershipMap;
    },
    getStoreMap(state){
        return state.storeMap;
    },
    getCouponsPlayMap(state){
        return state.CouponsPlayMap;
    },
    getBaiduMap(state){
        return state.baiduMap;
    }
}

export default ({
  state,
  getters,
  actions,
  mutations
})
